home *** CD-ROM | disk | FTP | other *** search
- Path: casbah.acns.nwu.edu!muzaffar
- From: muzaffar@casbah.acns.nwu.edu (Usman Muzaffar)
- Newsgroups: comp.lang.c
- Subject: Re: Sort Function
- Date: 1 Apr 1996 12:20:45 GMT
- Organization: Northwestern University, Evanston IL
- Message-ID: <4johmt$jee@news.acns.nwu.edu>
- References: <4jmq99$cqi@freenet-news.carleton.ca>
- NNTP-Posting-Host: casbah.acns.nwu.edu
-
- In article <4jmq99$cqi@freenet-news.carleton.ca>,
- Jerry Boyd <aq436@FreeNet.Carleton.CA> wrote:
- >
- >
- >How would I WRITE a function (called sort3) that would
- >sort three integers (in assending order) by using pointers
- >and NOT arrays?
- >
-
- I'm not sure what you mean by the caveat. I think most of the
- programmers here would agree that pointers and arrays are really two
- sides of the same coin - they're both a means of accesing memory;
- remember, a[6] is exactly the same as saying *(a+6). The brackets are
- just a convenient way of writing it.
-
- So if you mean you want your sort3() function to not use brackets,
- then just replace a[1] with *(a+1) and there you have it. The
- alternative is even more straightforard, if sort3 is passed it's
- arguments: sort3(int *a, int *b, int*c), then just use a series of
- inequaility operators to determine the answer and then use *a = xxx to
- actually set the values. Piece of cake.
-
- -usman
-
-
-
-